package decorator

// 装饰器模式 主要是为了扩展已存在的方法
// 生成对象由客户端决定

type DataSource interface {
	ReadData() string
	WriteData(data string)
}

type FileDataSource struct {
	data string
}

func (fds *FileDataSource) ReadData() string {
	return fds.data
}

func (fds *FileDataSource) WriteData(data string) {
	fds.data = data
}

type EncSourceDecorator struct {
	Wrappee DataSource
}

func (fds *EncSourceDecorator) ReadData() string {
	return fds.Wrappee.ReadData() + "解密"
}

func (fds *EncSourceDecorator) WriteData(data string) {
	fds.Wrappee.WriteData("加密" + data)
}

type AddSourceDecorator struct {
	Wrappee DataSource
}

func (fds *AddSourceDecorator) ReadData() string {
	return fds.Wrappee.ReadData() + "-衣服减少"
}

func (fds *AddSourceDecorator) WriteData(data string) {
	fds.Wrappee.WriteData("衣服增加-" + data)
}
